package com.older.wptsb.controller.community;


import com.older.wptsb.domain.dto.ElderDTO;
import com.older.wptsb.domain.po.Elder;
import com.older.wptsb.domain.po.RequireRole;
import com.older.wptsb.domain.po.UserRole;
import com.older.wptsb.domain.vo.CommunityVO;
import com.older.wptsb.domain.vo.ElderVO;
import com.older.wptsb.domain.vo.HealthDataVO;
import com.older.wptsb.service.CommunityElderService;
import com.older.wptsb.service.CommunityService;
import com.older.wptsb.util.Result;
import com.older.wptsb.util.UserContext;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/community")
public class CommunityElderController {

    @Resource
    private CommunityElderService communityElderService;

    @RequireRole({UserRole.ROLE_COMMUNITY})
    @GetMapping("/elderList")
    public Result<List<ElderVO>> getElderList() {
        List<ElderVO> elderList =  communityElderService.getElderList();
        return Result.success(elderList);
    }
    @RequireRole({UserRole.ROLE_COMMUNITY})
    @GetMapping("/elder/{id}")
    public Result<ElderVO> getElder(@PathVariable Integer id) {
        ElderVO elder = communityElderService.getElder(id);
        return Result.success(elder);
    }
    @RequireRole({UserRole.ROLE_COMMUNITY})
    @PostMapping("/addElder")
    public Result<String> addElder(@RequestBody ElderDTO elderDTO) {
        communityElderService.addElder(elderDTO);

        return Result.success("添加成功");
    }
    @RequireRole({UserRole.ROLE_COMMUNITY})
    @PutMapping("/updateElder")
    public Result<String> updateElder(@RequestBody ElderDTO elderDTO) {
        communityElderService.updateElder(elderDTO);
        return Result.success("修改成功");
    }
    @RequireRole({UserRole.ROLE_COMMUNITY})
    @DeleteMapping("/deleteElder/{id}")
    public Result<String> deleteElder(@PathVariable Integer id) {

        communityElderService.deleterElder(id);
        return Result.success("删除成功");
    }
    @RequireRole({UserRole.ROLE_COMMUNITY})
    @GetMapping("healthData")
    public Result<List<HealthDataVO>> getElderHealthData() {
        List<HealthDataVO> healthDataVOList = communityElderService.getElderHealthData();
        return Result.success(healthDataVOList);
    }
    @RequireRole({UserRole.ROLE_COMMUNITY})
    @GetMapping("healthData/{dataId}")
    public Result<List<HealthDataVO>> getElderHealthData(@PathVariable Integer dataId) {
        List<HealthDataVO> healthDataVO = communityElderService.getElderHealthDataById(dataId);
        return Result.success(healthDataVO);
    }
}
